/*
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2025-03-12 17:09:03
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2025-03-19 18:36:32
 */

const app = getApp()
// const beforeClose = (action) =>
//   new Promise((resolve) => {
//     setTimeout(() => {
//       if (action === 'confirm') {
//         resolve(true);
//       } else {
//         // 拦截取消操作
//         resolve(false);
//       }
//     }, 1000);
//   });
import {
  showMsg
} from '../../../../utils/config.js'
import {
  reqOrgList
} from '../../../../request/api'
Component({

  properties: {
    show: false,
    title: '',
    originValue: '',
    maxlength: { // 回显的时间
      type: Number,
      value: '40'
  }
  },
  options: {
    // addGlobalClass: true
  },

  data: {
    value: '',
  },

  observers: {

    show(val) {
      console.log('show', val);
      if (!val) return
      this.setData({
        value: this.data.originValue
      })
    }
  },
  async attached() {

  },
  detached() {},


  methods: {
    // 关闭前的回调函数
    beforeClose(action) {
      return new Promise((resolve) => {
        if (action === 'confirm') {
          // 如果输入框为空，阻止关闭
          if (!this.data.value) {
            wx.showToast({
              title: '请输入内容',
              icon: 'none',
            });
            resolve(false); // 阻止关闭
          } else {
            resolve(true); // 允许关闭
          }
        } else {
          // 拦截取消操作
          wx.showToast({
            title: '取消操作，阻止关闭',
            icon: 'none',
          });
          resolve(false); // 阻止关闭
        }
      });
    },
    async confirm() {

      const {
        value
      } = this.data
      console.log('value', value);
      if (!value) return showMsg(`请输入${this.data.title}`)
      this.triggerEvent('inputDialogHandle', {
        actionType: 'confirm',
        value
      });
      this.setData({
        value: ''
      })
    },
    onClose() {
      this.triggerEvent('inputDialogHandle', {
        actionType: 'cancel',
      });
      this.setData({
        value: ''
      })
    },
  }
})